<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Advertisement</title>
    <style>
        #main {
            font-family: Arial, sans-serif;
            margin: 20px;
        }

        h2 {
            color: #333;
        }

        img {
            max-width: 100%;
            height: auto;
        }

        #content {
            margin-top: 10px;
        }

        #adv_host {
            font-style: italic;
            color: #777;
        }

        #details {
            display: none;
        }

        #post_time {
            color: #aaa;
        }
    </style>
</head>
<body>

<div id="main" style="display: flex"
     onclick="reportClick(this)"
>
    <!--/*@thymesVar id="ad" type="org.example.advertisement_system.entity.Advertisement"*/-->
    <h2 th:text="${ad.title}" id="title"></h2>
    <img id="picture"
         th:src="'http://112.124.63.147:8080/'+${ad.picture}"
         th:alt="${ad.tag}"
         sizes="(max-width: 100%) 100vw, 100vw"
    >
<!--    <a th:href="'http://112.124.63.147:8080/'+${ad.link}">Link</a>-->
    </img>
    <p id="content" th:text="${ad.content}"></p>
    <p>powered by:</p>
    <p id="adv_host" th:text="${ad.username}"></p>
    <div id="details">
        <p id="post_time" th:text="${ad.time}"></p>
    </div>
</div>
<script type="application/javascript">
    function reportClick(element) {
        let title = element.getElementById("title").innerText;
        let addr = "112.124.63.147"
        let url = "http://" + addr + ":8080/api/effect/store?title=" + title;
        fetch(url, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            }
        }).then(response => {
            if (response.ok) {
                console.log('Reported successfully');
            } else {
                console.error('Failed to report');
            }
        });
    }

</script>

</body>
</html>